module WindSpirit
{
    export class GameData
    {
        static storeKey = "data";
        static localData = {
            record: 0,
            level: 1,
            musicOn: true,
            audioOn: true,
            isNewer: true,
            score: 0
        };
        static get score()
        {
            return this.localData.score;
        }
        static get level(): number
        {
            return this.localData.level;
        }
        static set level(level)
        {
            this.localData.level = level;
            this.saveData();
        }
        static upLevel()
        {
            this.level++;
        }
        static get isNewer()
        {
            return this.localData.isNewer;
        }
        static passNewer()
        {
            this.localData.isNewer = false;
            this.saveData();
        }
        static set score(score: number)
        {
            this.localData.score = score;
            if(score > this.record)
            {
                this.record = score;
            }
        }
        static get record(): number
        {
            return this.localData.record;
        }
        static set record(record: number)
        {
            this.localData.record = record;
            this.saveData();
        }
        static initData()
        {
            this.localData = JSON.parse(egret.localStorage.getItem(this.storeKey));
        }
        static saveData()
        {
            egret.localStorage.setItem(this.storeKey,JSON.stringify(this.localData));
        }
    }
}